const queryRules = {
	date: [
        {required: true, message: '请输选择日期范围', trigger: 'blur'}
    ]
}
			
let app = new Vue({
    el: "#app",
    data() {
        return {
        	leftbar_show:true,
			tableHeight:window.innerHeight- 90,
			pickerOptions: {
			  shortcuts: [{
				text: '最近一周',
				onClick(picker) {
				  const end = new Date()
				  const start = new Date()
				  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
				  picker.$emit('pick', [start, end])
				}
			  }, {
				text: '最近一个月',
				onClick(picker) {
				  const end = new Date();
				  const start = new Date();
				  start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
				  picker.$emit('pick', [start, end]);
				}
			  }, {
				text: '最近三个月',
				onClick(picker) {
				  const end = new Date();
				  const start = new Date();
				  start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
				  picker.$emit('pick', [start, end]);
				}
			  }]
			},
			tablecolums:[
				{"fixed":true,"prop":"dept", "label":"部门","width":"80"},
				{"fixed":true,"prop":"team", "label":"团队","width":"80"},
				{"fixed":true,"prop":"name", "label":"姓名","width":"80"},
				{"fixed":false,"prop":"total", "label":"跟踪","width":"50"},
				{"fixed":false,"prop":"weixin", "label":"微信","width":"50"},
				{"fixed":false,"prop":"A", "label":"A","width":"50"},
				{"fixed":false,"prop":"B", "label":"B","width":"50"},
				{"fixed":false,"prop":"C", "label":"C","width":"50"},
				{"fixed":false,"prop":"visited", "label":"面访","width":"50"},
				{"fixed":false,"prop":"signed", "label":"签约","width":"50"},
				{"fixed":false,"prop":"moveto", "label":"流转","width":"50"},
				{"fixed":false,"prop":"signnew", "label":"新签","width":"50"},
				{"fixed":false,"prop":"signcontinue", "label":"续签","width":"50"},
				{"fixed":false,"prop":"signold", "label":"转介绍","width":"50"},
				{"fixed":false,"prop":"amount", "label":"成交金额","width":"50"},
				{"fixed":false,"prop":"actualcollection", "label":"实际收款","width":"50"},
			],
			depts:[],
			teams:[],
			personnels:[],
			queryForm:{
                dept: [],
				team:[],
				personnel:[],
				date:[],
				userid:localStorage.getItem('USERID'),
				pageNo:1, // 当前页码
				pagesize:100 ,// 每页记录数
				pagesizes:[10,20,50,100,500]
			},
			pagetotal:0,
			pagedata:[],  // 当前页结果集
			loaded:false,
        }
    },
	methods: {
		// 显示侧边栏
		showLeftBar() {
			if (this.leftbar_show) {
				this.leftbar_show = false
			} else {
				this.leftbar_show = true
			}
		},
		start(){
			this.queryForm.pageNo = 1
			this.query()
		},
		// 查询
		async query() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				this.$refs.queryForm.validate(async valid => {
				    if (valid){
						let res = await axios.post('api/ststitrack/query', this.queryForm);
						if (res.code === 200) {
							// this.tablecolums = res.columns
							this.pagedata = res.data;
							this.pagetotal = res.total;
							this.$message.success(res.message);
						}else {
							this.$message.error(res.message);
						}
					}
				})			
			}catch (e) {
				this.$message.error('查询请求出错！', e.message);
			}
			
			// 关闭加载框
			loading.close();
		},
		
		// 设定表格当前页
		handleCurrentPageChange (selectedPageNo) {
		  this.queryForm.pageNo = selectedPageNo
		  // 加载数据页
		  this.query()
		},
		// 取得所有部门列表
		async getAllDept() {
			try {
				let res = await axios.get('api/alldept');
				if (res.code === 200) {
					this.depts = res.data;
					
				}else {
					this.$message.error(res.message);
				}
			}catch (e) {
				this.$message.error('部门列表请求出错！', e.message);
			}
		},
		// 取得所有主管
		async getLeader() {
			console.log(this.queryForm.dept)
			try {
				let res = await axios.post('api/leader/dept', this.queryForm.dept);
				if (res.code === 200) {
					this.teams = res.data;
				}else {
					this.$message.error(res.message);
				}
			}catch (e) {
				this.$message.error('主管列表请求出错！', e.message);
			}
		},
		// 取得成员
		async getPersonnel() {
			try {
				let res = await axios.post('api/user', this.queryForm);
				if (res.code === 200) {
					this.personnels = res.data;
				}else {
					this.$message.error(res.message);
				}
			}catch (e) {
				this.$message.error('主管列表请求出错！', e.message);
			}
		},
	},
	async mounted() {
		// 自动调整表格高度
		window.onresize = () => {
		  return (() => {
			this.tableHeight = window.innerHeight - 90
		  })()
		}
		// // 最近一周日期范围
		// const end = new Date()
		// const start = new Date()
		// start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
		// this.queryForm.date= [start, end]
		//初始化部门列表
		this.getAllDept();
	}

});	